#!/bin/python3
# -*- coding: utf-8 -*-

import carla

class SensorBase(object):
    def __init__(self,
                 name: str, 
                 sensor_type: str,
                 record: bool, 
                 record_root: str,
                 actor_attached: carla.Actor,
                 transform_attached: carla.Transform
                ):
        self.name = name + "_" + sensor_type
        self.type = sensor_type
        self.record = record
        self.record_root = record_root
        self.world = actor_attached.get_world()
        self.actor_attached = actor_attached
        self.transform_attached = transform_attached
        self.bp = self.world.get_blueprint_library().find(sensor_type)
        self.sensor = None
    
    def generate(self):
        self.sensor = self.world.spawn_actor(self.bp, self.transform_attached, attach_to=self.actor_attached)
        self.sensor.listen(self._callback)
        return self.sensor

    def _callback(self, data):
        print("sensorbase: {} recv one frame: ".format(self.name), data.frame)
    
    def destroy(self):
        self.sensor.destroy()